package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.common.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/setmeal")
public class SetmealController {
    @Autowired
    private SetmealService setmealService;

    @GetMapping("/page")
    @ApiOperation("分页查询")
    public Result<PageResult> findByPage( SetmealPageQueryDTO setmealPageQueryDTO){
        return Result.success(setmealService.findByPage(setmealPageQueryDTO));
    }


    @PostMapping
    @ApiOperation("新增套餐")
    public Result<String> save(@RequestBody SetmealDTO setmealDTO){
        return setmealService.save(setmealDTO);
    }

    @GetMapping("/{id}")
    @ApiOperation("查询套餐")
    public Result<SetmealVO> findById(@PathVariable Long id){
        return Result.success(setmealService.findById(id));
    }

    @PutMapping
    @ApiOperation("修改套餐")
    public Result<String> update(@RequestBody SetmealDTO setmealDTO){
        return setmealService.update(setmealDTO);
    }

    @DeleteMapping
    @ApiOperation("批量删除套餐")
    public Result<String> deleteByIds(@RequestParam Long[] ids){
        return setmealService.deleteByIds(ids);
    }



    @PostMapping("/status/{status}")
    @ApiOperation("起售、停售套餐")
    public Result<String> startOrStop(@PathVariable Integer status,Long id){
        return setmealService.startOrStop(status,id);
    }






}
